<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>My JSP 'bookBorrow.jsp' starting page</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->
<style type="text/css">
body{
font-size:12px;
}
div{
	width:500px;
	height:500px;
	
}
table{
	margin-left:50px;
	font-size:13px;
}

.bt{
width:80px;
margin-left:60px;
margin-top:30px;
}
td{
height:45px;
text-align:left;
}

</style>
  </head>
  
  <body>
  <div>
   <form action="jsp/book/bradd_list">
   
   <table>
   <tr><td>图书编号：</td>
   <td><input type="text" id="bid" name="bid"/></td>
   <td id="show"></td>
   </tr>
   <tr><td>读者编号：</td>
   <td><input type="text" id="rid" name="rid"/></td>
   <td id="show1"></td>
   </tr>
   <tr><td>借出时间：</td>
   <td><input type="text" name="outtime "onclick="new Calendar().show(this);" readonly="readonly"/></td>
   </tr>
   <tr><td>借阅天数：</td>
   <td><input type="text" id="day" name="day"/></td>
   <td id="show2"></td>
   </tr>
   </table>
     <input  type='submit' value='提交' class="bt" id="btn"/>
  <input  type='button' value='重置' class="bt" onclick="res()"/>
   </form>
   </div>
  </body>
    <script type="text/javascript" src="js/calendar.js"></script>
    <script type="text/javascript" src="js/jquery-1.7.2.js"></script>
    <script type="text/javascript">
    $(document).ready(function(){
    
  $("#btn").attr("disabled", true);
  $("#bid").blur(function(){
  var t=/^[0-9]*$/;
  var obj={};
  	obj.bid=$(this).val();
  	if($(this).val()==""||$.trim($(this).val()).length==0){
  	$('#show').text("请输入图书编号").css("color","red");
  	$("#btn").attr("disabled", true);
  	}else if(t.test($(this).val())){
  		$.post('<%= basePath%>jsp/book/bookjson_list',obj,cl,'json');
  	}else{
  		$('#show').text("请输入数字").css("color","red");
  	$("#btn").attr("disabled", true);
  	}
  });
  
  $("#day").blur(function(){
  var t=/^[0-9]*$/;
  	if(!t.test($(this).val())){
	$('#show2').text("请输入数字").css("color","red");
	 	$("#btn").attr("disabled", true);
  	}else if($(this).val()!=""&&$.trim($(this).val()).length!=0){
  	if($(this).val()=="0"){
  	$('#show2').text("不能为0").css("color","red");
  	$("#btn").attr("disabled", true);
  	}else{
  	$('#show2').text("OK").css("color","green");
	if($('#show1').text()=="Ok"&&$('#show').text()=="Ok")
	$("#btn").attr("disabled", false);
  	}

  	}else{
  	$('#show2').text("默认为30天").css("color","red");
  	if($('#show1').text()=="Ok"&&$('#show').text()=="Ok")
	$("#btn").attr("disabled", false);
  	
  	}
  

  });
$("#rid").blur(function(){
  var t=/^[0-9]*$/;
  var obj={};
  	obj.rid=$(this).val();
    obj.bid=$("#bid").val();
    
      if($(this).val()==""||$.trim($(this).val()).length==0){
  		$('#show1').text("请输入读者编号").css("color","red");
  		$("#btn").attr("disabled", true);
  	}else{
  	 if($('#show').text()=="Ok"){
  		if(t.test($(this).val())){
  			$.post('<%= basePath%>jsp/book/brjson_list',obj,rb,'json');
  		}else{
  			$('#show1').text("请输入数字").css("color","red");
  			$("#btn").attr("disabled", true);
  			}
    }else{
    $('#show').text("请输入图书编号");
    }
  	}
   
  	
  });
    });
      function cl(data){
  	if(data.state=="1"){
  	$('#show').text("Ok").css("color","green");
  	if($('#show1').text()=="Ok" &&$('#show2').text()!="不能为0"&&$('#show2').text()!="请输入数字")
    	$("#btn").attr("disabled", false);
  	}else if(data.state=="0"){
  	$('#show').text("没有此图书").css("color","red");
  		  $("#btn").attr("disabled", true);
  	}else{
  	$('#show').text("已借完").css("color","red");
  		  $("#btn").attr("disabled", true);
  	}
  	}
  	
function rb(data){
  	if(data.state=="2"){
  	$('#show1').text("Ok").css("color","green");
  	if($('#show').text()=="Ok"&&$('#show2').text()!="不能为0"&&$('#show2').text()!="请输入数字")
    	$("#btn").attr("disabled", false);
  	}else if(data.state=="0"){
  	$('#show1').text("没有该读者").css("color","red");
  		  $("#btn").attr("disabled", true);
  	}else{
  	$('#show1').text("押金不足").css("color","red");
  		  $("#btn").attr("disabled", true);
  	}
  	}
  	  	function res(){
  	$("#btn").attr("disabled", true);
$('table input').val("");
	$('#show').text("");
	$('#show2').text("");
		$('#show1').text("");
  	}
    </script>
</html>
